import java.util.StringTokenizer;


class P423_39643 {

	public static void main(String[] args) {
		
		String line = readLn();
		
		
		while (line != null) {
			process(Integer.parseInt(line));
			line = readLn();
		}
		
	}
	
	private static void process(int n) {
		int[][] board = new int[n][n];
		
		for (int k = 0; k < n; k++)
			for (int j = 0; j < n; j++) {
				board[k][j] = 99999999;
			}

		for (int k = 0; k < n - 1; k++) {
			StringTokenizer st = new StringTokenizer(readLn());
			
			for (int j = 0; j < k + 1; j++) {
				String xSt = st.nextToken();
				if ("x".equals(xSt)) {
					board[j][k+1] = 99999999;
					board[k+1][j] = 99999999;
				} else {
					int x = Integer.parseInt(xSt);
					board[j][k+1] = x;
					board[k+1][j] = x;
				}
			}
			
		}
		
//		print (board);
		
		floydWarshall(board);
		
		int max = Integer.MIN_VALUE;
		
		for (int k = 0; k < board.length; k++) {
			if (board[0][k] != 99999999)
				if (board[0][k] > max) max = board[0][k];
		}
		
		System.out.println(max);
		
		
	}

	private static void print(int[][] board) {
		for (int k = 0; k < board.length; k++) {
			for (int j = 0; j < board.length; j++) {
				if (board[k][j] == 99999999) 
					System.out.print("oxo\t");
				else System.out.print(board[k][j] + "\t");
			}
			System.out.println();
		}
		
	}

	private static void floydWarshall(int[][] board) {
		for (int k = 0; k < board.length; k++)
			board[k][k] = 0;
		
		
		for (int k = 0; k < board.length; k++) {
			for (int i = 0; i < board.length; i++) {
				for (int j = 0; j < board.length; j++) {
					if (board[i][j] > board[i][k] + board[k][j]) {
						board[i][j] = board[i][k] + board[k][j];
					}
				}
			}
		}
		
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

}
